package com.ayu.chatroom.service.impl;

import com.ayu.chatroom.entity.MyFriends;
import com.ayu.chatroom.entity.vo.MyFriendVo;
import com.ayu.chatroom.mapper.MyFriendsMapper;
import com.ayu.chatroom.service.MyFriendsService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author ayu
 * @since 2022-10-10
 */
@Service
public class MyFriendsServiceImpl extends ServiceImpl<MyFriendsMapper, MyFriends> implements MyFriendsService {


    private final MyFriendsMapper myFriendsMapper;

    @Autowired
    public MyFriendsServiceImpl(MyFriendsMapper myFriendsMapper) {
        this.myFriendsMapper = myFriendsMapper;
    }

    @Override
    public Integer verifyMyFriendExist(String myUserId, String friendUserId) {

        QueryWrapper<MyFriends> queryWrapper = new QueryWrapper<>();

        queryWrapper.eq("my_user_id", myUserId);

        queryWrapper.eq("my_friend_user_id", friendUserId);

        int count = this.count(queryWrapper);

        return count;


    }

    @Override
    public void addFriends(String userId, String friendUserId) {


        MyFriends friends = new MyFriends();

        friends.setMyUserId(userId);
        friends.setMyFriendUserId(friendUserId);

        this.save(friends);

    }

    @Override
    public List<MyFriendVo> getFriendsList(String userId) {
        return myFriendsMapper.getFriendsList(userId);
    }
}
